package com.pilipala.utils;

import com.pilipala.properties.MailProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

public class EmailUtil {

    @Autowired
    JavaMailSender mailSender;
    /**
     * 发送email
     *
     * @param mailProperties 配置文件
     */
    public void send(MailProperty mailProperties, String toMail, String text, String subject){
//        发送器
//        消息体
        SimpleMailMessage mailMessage = new SimpleMailMessage();
//        发送源
        mailMessage.setFrom(mailProperties.getUsername());
//        接受源
        mailMessage.setTo(toMail);
//        主题
        mailMessage.setSubject(subject);
//        消息体
        mailMessage.setText(text);

        mailSender.send(mailMessage);
    }
}

